"""
Copyright (c) 2023 - present SKbioinfo
"""

from apps.NGS_API.connect import MysqlConnection

def get_user_info(user:str):
    ### set up MYSQL connection ###
    db_conn=MysqlConnection()
    ### SQL: current user group query sql ###
    group_query_sql = '''
    SELECT
        ro.group
    FROM users as us INNER JOIN
        roles as ro ON us.role_id = ro.name
    WHERE us.username = \"{user}\"
    '''.format(
        user = user
    )
    group = db_conn.Query(group_query_sql)[0][0]
    ### SQL: user_base_info_sql ###
    user_base_info_sql = ""
    if group in ["NGS","MS"]:
        user_base_info_sql = '''
        SELECT
            us.id,
            us.username,
            us.role_id,
            us.email,
            us.create_time,
            ro.detail,
            ro.permissions,
            ro.group
        FROM users as us INNER JOIN
            roles as ro ON us.role_id = ro.name
        WHERE ro.group = \"{group}\"
        '''.format(
            group = group
        )
    elif group in ["Super"]:
        user_base_info_sql = '''
        SELECT
            us.id,
            us.username,
            us.role_id,
            us.email,
            us.create_time,
            ro.detail,
            ro.permissions,
            ro.group
        FROM users as us INNER JOIN
            roles as ro ON us.role_id = ro.name
        '''
    user_base_info = db_conn.Query(user_base_info_sql)
    db_conn.close_conn()
    return user_base_info